﻿@using OTE.Web.Infrastructure.Helper
@model OTE.Web.Mvc.ViewModels.Category.CategoryListViewModel
@{
    ViewBag.Title = "Index";
    Layout = "~/Areas/Admin/Views/Shared/_Layout.cshtml";
}
@using OTE.Web.Infrastructure.Utils
<!--  start page-heading -->
<div id="page-heading">
    <h1>
        Category Management</h1>
</div>
<!-- end page-heading -->
<table border="0" width="100%" cellpadding="0" cellspacing="0" id="content-table">
    <tr>
        <th rowspan="3" class="sized">
            <img src="@Url.Image("shared/side_shadowleft.jpg")" width="20" height="300" alt="" />
        </th>
        <th class="topleft">
        </th>
        <td id="tbl-border-top">
            &nbsp;
        </td>
        <th class="topright">
        </th>
        <th rowspan="3" class="sized">
            <img src="@Url.Image("shared/side_shadowright.jpg")" width="20" height="300" alt="" />
        </th>
    </tr>
    <tr>
        <td id="tbl-border-left">
        </td>
        <td>
            <!--  start content-table-inner ...................................................................... START -->
            <div id="content-table-inner">
                <!--  start table-content  -->
                <div id="table-content">
                    <!--  start message-red -->
                    <div id="message-red">
                        <table border="0" width="100%" cellpadding="0" cellspacing="0">
                            <tr>
                                <td class="red-left">
                                    Red message
                                </td>
                                <td class="red-right">
                                    <a class="close-red">
                                        <img alt="" src="@Url.Image("table/icon_close_red.gif")" /></a>
                                </td>
                            </tr>
                        </table>
                    </div>
                    <!--  end message-red -->
                    <!--  start table ..................................................................................... -->
                    <form id="mainform" action="">
                    <table border="0" width="100%" cellpadding="0" cellspacing="0" id="product-table">
                        <tr>
                            <th class="table-header-check">
                                <a id="toggle-all"></a>
                            </th>
                            <th class="table-header-repeat line-left minwidth-1">
                                <label>
                                    Name</label>
                            </th>
                            <th class="table-header-repeat line-left minwidth-1">
                                <label>
                                    Parent</label>
                            </th>
                            <th class="table-header-options line-left">
                                <label>
                                    Option</label>
                            </th>
                        </tr>
                        @foreach (var item in Model.Categories)
                        {
                            <tr>
                                <td>
                                    <input value="@item.Id" type="checkbox" />
                                </td>
                                <td>
                                    @item.Name
                                </td>
                                <td>
                                    Parent Category
                                </td>
                                <td class="options-width">
                                    @Html.ActionLink(" ", "Edit", new { area = "Admin", controller = "Category", id = item.Id }, new { @class = "icon-1 info-tooltip" })
                                    @Html.ActionLink(" ", "Delete", new { area = "Admin", controller = "Category", id = item.Id }, new { @class = "icon-2 info-tooltip", onclick = "return ConfirmDelete();" })
                                </td>
                            </tr>
                        }
                    </table>
                    </form>
                </div>
                <!--  end content-table  -->
                <!--  start actions-box ............................................... -->
                <div id="actions-box">
                    @*<h3><a href="<%= Utils.ResolveUrl(this.Html, "~/Admin/Category/Add") %>"><img width="21" height="21" alt="" src="<%= Utils.ResolveUrl(this.Html, "~/") %>images/admin/forms/icon_plus.gif"> Thêm danh mục</a></h3>*@
                    <a href="" class="action-slider"></a>
                    <div id="actions-box-slider">
                        @Html.ActionLink("Create", "Create", new { area = "Admin", controller = "Category" }, new { @class = "action-edit" })
                        @Html.ActionLink("Delete All", "DeleteAll", new { area = "Admin", controller = "Category" }, new { @class = "action-delete", onclick = "return SubmitDelete(this);" })
                    </div>
                    <div class="clear">
                    </div>
                </div>
                <!-- end actions-box........... -->
                <!--  start paging..................................................... -->
                <table border="0" cellpadding="0" cellspacing="0" id="paging-table">
                    <tr>
                        <td>
                            @if ((int)ViewData[Constants.TOTAL_PAGE] > 1)
                            {
                                string prePage = ((int)ViewData[Constants.PAGE_INDEX] - 1) < 1 ? "1" : ((int)ViewData[Constants.PAGE_INDEX] - 1).ToString();
                                string nextPage = ((int)ViewData[Constants.PAGE_INDEX] + 1) > (int)ViewData[Constants.TOTAL_PAGE] ? ViewData[Constants.TOTAL_PAGE].ToString() : ((int)ViewData[Constants.PAGE_INDEX] + 1).ToString();

                                if ((int)ViewData[Constants.PAGE_INDEX] > 1)
                                {
                                <a class = "page-far-left" href="@(Url.Content("~/Category/Paging/1"))"></a>
                                <a class = "page-left" href="@(Url.Content("~/Category/Paging/" + prePage))"></a>
                                }
                                <div id="page-info">
                                    Trang <strong>@ViewData[Constants.PAGE_INDEX]</strong> / @ViewData[Constants.TOTAL_PAGE]</div>

                                if ((int)ViewData[Constants.PAGE_INDEX] < (int)ViewData[Constants.TOTAL_PAGE])
                                {
                                <a class = "page-right" href="@(Url.Content("~/Category/Paging/" + nextPage))"></a>
                                <a class = "page-far-right" href="@(Url.Content("~/Category/Paging/" + ViewData[Constants.TOTAL_PAGE].ToString()))">
                                </a>
                                }
                            }
                        </td>
                    </tr>
                </table>
                <!--  end paging................ -->
                <div class="clear">
                </div>
            </div>
        </td>
        <td id="tbl-border-right">
        </td>
    </tr>
    <tr>
        <th class="sized bottomleft">
        </th>
        <td id="tbl-border-bottom">
            &nbsp;
        </td>
        <th class="sized bottomright">
        </th>
    </tr>
</table>
<script type="text/javascript">
    function ConfirmDelete() {
        var res = confirm("Do you want to delete it?");

        return res;
    }

    function SubmitDelete(obj) {
        var ids = "";
        $(".ui-helper-hidden-accessible").each(function () {
            if (ids == "")
                ids += this.value;
            else
                ids += "," + this.value;
        });

        location.href = obj.href + "/" + ids;
        return false;
    }
</script>